package com.lionxing.DNTG;

import org.cocos2d.sound.SoundEngine;

import android.content.Context;

public class playSound extends Object{
	
	private Context cocos2dcontext;
	
	private boolean _soundPlaying = false;
	private boolean _soundPaused = false;
	
	private float _effectsound = -1.0f;
	
	 private static playSound _sharedDirector = new playSound();
	 
	    /** returns a shared instance of the director */
	    public static playSound sharedDirector() {
	      
	            return _sharedDirector;

			//
			// Default Director is TimerDirector

	    }
	    
	    protected playSound()
	    {
	    	
	    	
	    }
	    
	    public void setContext(Context context)
	    {
	    	cocos2dcontext = context;
	    	
	    }
	    
	    public void playbgSound(int id, boolean loop)
	    {
	    	if(_soundPlaying)
	    	{
	    		return ;
	    	}
	    	
	    	if(cocos2dcontext != null)
	    	{
	    		SoundEngine.sharedEngine().playSound(cocos2dcontext, id, loop);
	    		
	    		_soundPlaying = true;
	    		
	    		
	    		float tmpfloat=  Float.parseFloat(filemanager.sharedDirector().getHashmapgameinfo().get("bgsound").toString());
	    		
	    		tmpfloat = tmpfloat/100.0f;
	    		
	    		SoundEngine.sharedEngine().setSoundVolume(tmpfloat);
	    	}
	    	
	    }
	    
	    public void playEffectSound(int id)
	    
	    {
	    	
	    	if(cocos2dcontext != null)
	    	{
	    		float tmpfloat=  Float.parseFloat(filemanager.sharedDirector().getHashmapgameinfo().get("bgsound").toString());
	    		
	    		tmpfloat = tmpfloat/100.0f;
	    		
	    		if(_effectsound != tmpfloat)
	    		{
	    			SoundEngine.sharedEngine().setEffectsVolume(tmpfloat);
	    			
	    			_effectsound = tmpfloat;
	    		}
	    		
	    		
	    	
	    		SoundEngine.sharedEngine().playEffect(cocos2dcontext, id);
	    	}
	    }
	    
	    public void reloadBgsound(int id)
	    {
	    	
	    	if(cocos2dcontext != null)
	    	{
	    		SoundEngine.sharedEngine().preloadSound(cocos2dcontext, id);
	    	}
	    }
	    
	    public void reLoadEffectSound(int id)
	    {
	    	
	    	if(cocos2dcontext != null)
	    	{
	    		
	    		SoundEngine.sharedEngine().preloadEffect(cocos2dcontext, id);
	    	}
	    }
	    
	    public void PaushedSound()
	    {
	    	if(_soundPaused)
	    	{
	    		return;
	    		
	    	}
	    	
	   		SoundEngine.sharedEngine().pauseSound();
    		
    		_soundPaused = true;
    		_soundPlaying = false;
	    	
	    }
	    
	    public void ResumeSound ()
	    {
	    	
	    	if(_soundPaused)
	    	{
	    	
	    		SoundEngine.sharedEngine().resumeSound();
	    		
	    		_soundPaused = false;
	    	}
	    }
	    
	    public void SetBgSoundvolume(float volume)
	    {
	    	
	    	SoundEngine.sharedEngine().setSoundVolume(volume);
	    }
	    
	    public void SetEffectSoundvolume(float volume)
	    {
	    	
	    	SoundEngine.sharedEngine().setEffectsVolume(volume);
	    }
	    
	    public void destory()
	    {
	    	
	    	//SoundEngine.sharedEngine().pauseSound();
	    	_soundPlaying = false;
	    	_soundPaused = false;
	    	
	    	SoundEngine.sharedEngine().realesAllEffects();
	    	SoundEngine.sharedEngine().realesAllSounds();
	    	
	    	SoundEngine.sharedEngine().purgeSharedEngine();
	    }

}
